package com.sinoglobal.sinostore.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.sinoglobal.sinostore.R;
import com.sinoglobal.sinostore.bean.ShopWareTypeVo;
import com.sinoglobal.sinostore.system.Constants;
import com.sinoglobal.sinostore.utils.BitmapHelp;

public class ActivityShopCityAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<ShopWareTypeVo> arrayList;
	private BitmapUtils bitmapUtils;

	public ActivityShopCityAdapter(Context context, ArrayList<ShopWareTypeVo> arrayList) {
		super();
		this.context = context;
		this.arrayList = arrayList;
		// 计算出单个类目的宽高
		bitmapUtils = BitmapHelp.getBitmapUtils(context);
	}

	public ArrayList<ShopWareTypeVo> getArrayList() {
		return arrayList;
	}

	public void setArrayList(ArrayList<ShopWareTypeVo> arrayList) {
		if (null != arrayList) {
			this.arrayList = arrayList;
		}
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return arrayList.size();
	}

	@Override
	public ShopWareTypeVo getItem(int position) {
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		if (null == convertView) {
			convertView = LayoutInflater.from(context).inflate(R.layout.shop_city_gridview_item, null);
		}
		TextView imageView = ViewHolder.getViewById(convertView, R.id.text);
		ImageView image = ViewHolder.getViewById(convertView, R.id.image);
		if (position == 0) {
			image.setImageDrawable(context.getResources().getDrawable(R.drawable.shop_mall_home_btn_default1));
		} else {
			bitmapUtils.display(image, Constants.PIC_HOST + arrayList.get(position).getOriginal_url());
		}
		imageView.setText(arrayList.get(position).getName());
		return convertView;
	}
}
